package org.ohos.rajawali3d.examples.wallpaper;


import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;
import org.ohos.rajawali3d.ResourceTable;
import org.ohos.rajawali3d.examples.PreferencesLocal;

/**
 * @author Jared Woolston (jwoolston@tenkiv.com)
 */
public class FragmentPreferences extends Fraction implements Preferences.PreferencesObserver {

    private Preferences mSharedPreferences;
    private DatabaseHelper mDatabaseHelper;

    private int[] preferencesToLoad() {
        return new int[]{ /*R.xml.preferences*/};
    }

    @Override
    public void onStart(Intent savedInstanceState) {
        super.onStart(savedInstanceState);
        mDatabaseHelper = new DatabaseHelper(getContext());
        mSharedPreferences = mDatabaseHelper.getPreferences(PreferencesLocal.PreferencesLocal_NAME);

        // Load defined preferences
//        for (int preferenceResource : preferencesToLoad()) {
//            addPreferencesFromResource(preferenceResource);
//        }
    }

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        scatter.parse(ResourceTable.Layout_preferences, container, true);
        return super.onComponentAttached(scatter, container, intent);
    }

    @Override
    public void onActive() {
        super.onActive();
        mSharedPreferences.registerObserver(this);
    }

    @Override
    public void onInactive() {
        super.onInactive();
        mSharedPreferences.unregisterObserver(this);
    }

    @Override
    public void onChange(Preferences sharedPreferences, String key) {

    }

//    @Override
//    public boolean onPreferenceChange(Preference preference, Object newValue) {
//        return false;
//    }
}
